# This program covers tutorials 6,7,8, 9, 10 of youtube-theReimber
# Demonstrates the use of menus, and the message box
# Selecting and opening files through filedialog()
# Using the colorchooser
# Adding checkable items in the menu.



import sys
from tkinter import *
from tkinter import messagebox
from tkinter import colorchooser 
from tkinter import filedialog


mainWindow = Tk()
mainWindow.geometry("200x100+200+200")
mainWindow.title("Menus")

def clickedFileNew():
    print("You clicked new")
    return

def clickedFileExit():
    confirmExit = messagebox.askyesno(title="Confirm exit", message="Are you sure you wish to exit..?")
    if confirmExit:
        mainWindow.destroy()
        return

def clickedFileColorPalette():
    color = colorchooser.askcolor()
    print("You selected: ", str(color))
    
def clickedFileOpen():
    filename = filedialog.askopenfilename()
    print("You selected to open file: ", filename)
    fileObj = open(filename, "r")
    print(fileObj.read())
    fileObj.close()

def clickedCut():
    print("You clicked cut")
    return

def clickedAbout():
    messagebox.showinfo(title="About me", message="Jerk turned Niceguy.. \n(occasionally the jerk visits for short periods)")
    messagebox.showerror(title="About me", message="Jerk turned Niceguy.. \n(occasionally the jerk visits for short periods)")
    messagebox.showwarning(title="About me", message="Jerk turned Niceguy.. \n(occasionally the jerk visits for short periods)")
    sure = messagebox.askyesno(title="About me", message="are you sure or not")
    if sure==True:
        print("Bacha sure hai waloo")
    else:
        print("ScheiBe")
        return


# Make the menu bar in parent window
menuBar = Menu(mainWindow)

# Create the file menu container
fileMenu = Menu(menuBar, tearoff=0)
# Populating the file menu with items
fileMenu.add_command(label="New", command=clickedFileNew)                       # Items in the list
fileMenu.add_command(label="Open", command=clickedFileOpen)                     #         //
fileMenu.add_command(label="Save As..")                                         #         //
fileMenu.add_command(label="Color pallette", command=clickedFileColorPalette)   #         //
fileMenu.add_command(label="Exit", command=clickedFileExit)                     #         //
# Add the populated file menu to the menu bar in the parent window
menuBar.add_cascade(label="File", menu=fileMenu)                                # Top level label     


editMenu = Menu(menuBar)
editMenu.add_command(label="Cut", command=clickedCut)
editMenu.add_command(label="Copy")
editMenu.add_command(label="Paste")
editMenu.add_command(label="Undo")
menuBar.add_cascade(label="Edit", menu=editMenu)    # Top level label

helpMenu = Menu(menuBar, tearoff=0)
helpMenu.add_command(label="About", command=clickedAbout)
menuBar.add_cascade(label="Help", menu=helpMenu) 


# Adding checkable items to the menu bar
setupMenu = Menu(menuBar, tearoff=0)
setupMenu.add_checkbutton(label="checkable")
menuBar.add_cascade(label="Setup", menu=setupMenu)




mainWindow.config(menu=menuBar)

mainWindow.mainloop()